/**
 * Created by DukeCrushIt on 2015/7/27.
 */
var communicator =  {
    heartbeat :function(){
        yingo.ajax({
            url: "/api/game/heartbeat",
            params: {},
            codes:window.codes,
            callback: function () {
                egret.getDefinitionByName("game.QZoneConfig").heartBeat("");
            }
        })
    },
    login:function(){
        yingo.ajax({
            url: "/api/user/login",
            params: {},
            codes:window.codes,
            callback: function (result) {
                QZoneConfig = egret.getDefinitionByName("game.QZoneConfig");
                QZoneConfig.updateUserInfo(result,true);
                communicator.heartbeat(); //登录后才开始心跳s
                communicator.list();
                communicator.zoneInfo();
            }
        })
    },
    info: function(data){//玩家信息
        yingo.ajax({
            url: '/api/user/info',
            params: {},
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.updateUserInfo(result);
            }
        })
    },
    charge:function(propId,count){//充值
        yingo.ajax({
            params:{propId:propId,count:count},//propId和count不能同时为0，propId为购买的充值包道具id
            url : '/api/user/charge',
            codes:window.codes,
            callback : function(result){
                QZoneConfig.chargeResult(result);
            }
        })
    },
    pay:function(orderId){//充值
        yingo.ajax({
            params:{orderId:orderId},//propId和count不能同时为0，propId为购买的充值包道具id
            url : '/api/user/pay',
            codes:window.codes,
            callback : function(result){
                QZoneConfig.payResult(result);
            }
        })
    },
    buy_prop: function(propid,payType, count){//购买道具
        yingo.ajax({
            params:{propId:propid,payType:payType, count:count},
            url: '/api/prop/buy',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.buyPropResult(result);
            }
        })
    },
    use_prop: function(propid,count){//使用道具
        yingo.ajax({
            params:{propId:propid,count:count},
            url: '/api/user/use_prop',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.usePropResult(result);
            }
        })
    },
    goods: function(){//物品列表
        yingo.ajax({
            url: '/api/data/goods',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.goodsInfo(result);
                communicator.decoratemodels();
                communicator.props();
            }
        })
    },
    props: function(){
        yingo.ajax({
            params : {},
            url: '/api/user/props',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onGetProps(result);
                communicator.models();
            }
        })
    },
    zoneInfo: function(){
        yingo.ajax({
            params : {},
            codes:window.codes,
            url: '/api/user/zoneInfo',
            callback: function (result) {
                QZoneConfig.onZoneInfo(result);
                //communicator.lattention();
                communicator.goods();
            }
        })
    },
    rankPage: function(type){
        yingo.ajax({
            params : {type:type},
            url: '/api/rank/page',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onRankPage(result);
            }
        })
    },
    gift: function(expend){
        yingo.ajax({
            params : {expend:expend},
            url: '/api/user/gift',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onGift(result);
            }
        })
    },
    guide: function(step){
        yingo.ajax({
            params : {step:step},
            url: '/api/user/guide',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onGuideBack(result);
            }
        })
    },
    buy: function(name,petId,sex){
        yingo.ajax({
            params : {name:name,petId:petId,sex:sex},
            url: '/api/pet/buy',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onBuyPet(result);
            }
        })
    },
    list: function(){
        yingo.ajax({
            params : {},
            url: '/api/pet/list',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onPetList(result);
                communicator.hairs();
            }
        })
    },
    hairs: function(){
        yingo.ajax({
            params : {},
            url: '/api/pet/hairs',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onHairs(result);
            }
        })
    },
    fondle: function(petId){
        yingo.ajax({
            params : {petId:petId},
            url: '/api/pet/fondle',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onFondleBack(result);
            }
        })
    },
    click: function(petId,times){
        yingo.ajax({
            params : {petId:petId,times:times},
            url: '/api/pet/click',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onClickBack(result);
            }
        })
    },
    auto: function(){
        yingo.ajax({
            params : {},
            url: '/api/pet/auto',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onAutoBack(result);
                communicator.missionList();
            }
        })
    },
    glean: function(petId,hairs,type){
        yingo.ajax({
            params : {petId:petId,hairs:hairs,type:type},
            url: '/api/pet/glean',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onGleanBack(result);
            }
        })
    },
    upgrade: function(petId){
        yingo.ajax({
            params : {petId:petId},
            url: '/api/pet/upgrade',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onUpgradeBack(result);
            }
        })
    },
    indate: function(petId,slogan){
        yingo.ajax({
            params : {petId:petId,slogan:slogan},
            url: '/api/pet/indate',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onIndateBack(result);
            }
        })
    },
    date: function(userId){
        yingo.ajax({
            params : {dateUser:userId},
            url: '/api/pet/date',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onDateBack(result);
            }
        })
    },
    dateRefresh: function(){
        yingo.ajax({
            params : {},
            url: '/api/pet/dateRefresh',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onDateList(result);
            }
        })
    },
    dateInfo: function(){
        yingo.ajax({
            params : {},
            url: '/api/pet/dateInfo',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onDateInfo(result);
            }
        })
    },
    dateSweep: function(recordId){
        yingo.ajax({
            params : {recordId:recordId},
            url: '/api/pet/dateSweep',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onSweep(result);
            }
        })
    },
    petCount: function(){
        yingo.ajax({
            params : {},
            url: '/api/rank/petCount',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onPetCount(result);
            }
        })
    },
    petSex: function(){
        yingo.ajax({
            params : {},
            url: '/api/rank/petSex',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onPetSex(result);
            }
        })
    },
    petHairs: function(){
        yingo.ajax({
            params : {},
            url: '/api/rank/petHairs',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onPetHairs(result);
            }
        })
    },
    userHair: function(){
        yingo.ajax({
            params : {},
            url: '/api/rank/userHair',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onUserHair(result);
            }
        })
    },
    userPopularity: function(page){
        yingo.ajax({
            params : {page:page},
            url: '/api/rank/userPopularity',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onUserPopularity(result);
            }
        })
    },
    robHairs: function(page){
        yingo.ajax({
            params : {page:page},
            url: '/api/rank/pillage-hairs',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onRobHairs(result);
            }
        })
    },
    petHair: function(){
        yingo.ajax({
            params : {},
            url: '/api/rank/petHair',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onPetHair(result);
            }
        })
    },
    petFondle: function(){
        yingo.ajax({
            params : {},
            url: '/api/rank/petFondle',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onPetFondle(result);
            }
        })
    },
    use: function(propId,petId){
        yingo.ajax({
            params : {propId:propId, petId:petId},
            url: '/api/prop/use',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onPropUseResult(result);
            }
        })
    },
    setFigure:function(petId, data){
        yingo.ajax({
            params : {petId:petId, data:data},
            url: '/api/pet/setFigure',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onFigureBack(result);
            }
        })
    },
    buffs: function(){
        yingo.ajax({
            params : {},
            url: '/api/prop/buffs',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onBuffsBack(result);
            }
        })
    },
    updateSlogan: function(petId,slogan){
        yingo.ajax({
            params : {petId:petId, slogan:slogan},
            url: '/api/pet/updateSlogan',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onSloganBack(result);
            }
        })
    },
    models: function(){
        yingo.ajax({
            params : {},
            url: '/api/mission/models',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onMissionModels(result);
                communicator.missionList();
            }
        })
    },
    missionList: function(){
        yingo.ajax({
            params : {},
            url: '/api/mission/list',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onMissionlist(result);
            }
        })
    },
    missionAward: function(missionId){
        yingo.ajax({
            params : {missionId:missionId},
            url: '/api/mission/award',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onMissionAward(result);
            }
        })
    },
    signInfo: function(){
        yingo.ajax({
            params : {},
            url: '/api/user/signInfo',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onSignInfo(result);
            }
        })
    },
    sign: function(){
        yingo.ajax({
            params : {},
            url: '/api/user/sign',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onSign(result);
            }
        })
    },
    maillist: function(pageIndex, pageSize){
        yingo.ajax({
            params : {pageIndex:pageIndex,pageSize:pageSize},
            url: '/api/mail/list',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onMailList(result);
            }
        })
    },
    readmail: function(mailId){
        yingo.ajax({
            params : {mailId:mailId},
            url: '/api/mail/read',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onReadMail(result);
            }
        })
    },
    deleteMail: function(mailIds){
        yingo.ajax({
            params : {mailIds:mailIds},
            url: '/api/mail/delete',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onDeleteMail(result);
            }
        })
    },
    mailAward: function(mailId){
        yingo.ajax({
            params : {mailId:mailId},
            url: '/api/mail/award',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onMailAward(result);
            }
        })
    },
    changeRear: function(petid){
        yingo.ajax({
            params : {petId:petid},
            url: '/api/pet/changeRear',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onChangeRearBack(result);
            }
        })
    },
    unlocks: function(){
        yingo.ajax({
            params : {},
            url: '/api/pet/unlocks',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onUnlocks(result);
            }
        })
    },
   dunlocks: function(){
        yingo.ajax({
            params : {},
            url: '/api/pwar/unlocks',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onDecUnlocks(result);
            }
        })
    },
    decoratemodels: function(){
        yingo.ajax({
            params : {},
            url: '/api/pwar/models',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onDecorateModels(result);
                communicator.dunlocks();
            }
        })
    },
    dressup: function(petid,items){
        yingo.ajax({
            params : {petId:petid,items:items},
            url: '/api/pwar/dressup',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onDressed(result);
            }
        })
    },
    iwars: function(petid){
        yingo.ajax({
            params : {petId:petid},
            url: '/api/pwar/lwars',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onlwars(result);
            }
        })
    },
    iornaments: function(){
        yingo.ajax({
            params : {},
            url: '/api/pwar/lornaments',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onDocorates(result);
            }
        })
    },
    buydecorates: function(petid, goodsIds,flag){
        yingo.ajax({
            params : {petId:petid, goodsIds:goodsIds, flag:flag},
            url: '/api/pwar/buy',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onDecoratesBuy(result);
            }
        })
    },
    search: function(searchId){
        yingo.ajax({
            params : {searchId:searchId},
            url: '/api/pet/search',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onSearchBack(result);
            }
        })
    },
    attention: function(attentionId){
        yingo.ajax({
            params : {attentionId:attentionId},
            url: '/api/trip/attention',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onAttentionBack(result);
            }
        })
    },
    unattention: function(attentionId){
        yingo.ajax({
            params : {attentionId:attentionId},
            url: '/api/trip/unattention',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onUnattentionBack(result);
            }
        })
    },
    praise: function(attentionId){
        yingo.ajax({
            params : {praiseId:attentionId},
            url: '/api/trip/praise',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onPraiseBack(result);
            }
        })
    },
    handsel: function(attentionId,goodsId){
        yingo.ajax({
            params : {handselId:attentionId,goodsId:goodsId},
            url: '/api/trip/handsel',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onGiftBack(result);
            }
        })
    },
    pillage: function(pillageId){
        yingo.ajax({
            params : {pillageId:pillageId},
            url: '/api/pet/pillage',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onStartPillageBack(result);
            }
        })
    },
    pillageFinish: function(bloodPer){
        yingo.ajax({
            params : {bloodPer:bloodPer},
            url: '/api/pet/finish',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onFinishPillageBack(result);
            }
        })
    },
    revenge: function(mailId){
        yingo.ajax({
            params : {mailId:mailId},
            url: '/api/pet/revenge',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onRevengeBack(result);
            }
        })
    },
    cleancd: function(){
        yingo.ajax({
            params : {},
            url: '/api/pet/cleancd',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onCleanCdBack(result);
            }
        })
    },
    lattention: function(){
        yingo.ajax({
            params : {},
            url: '/api/trip/lattention',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onAttentionList(result);
            }
        })
    },
    popularity: function(userId){
        yingo.ajax({
            params : {userId:userId},
            url: '/api/trip/popularity',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onPopularityBack(result);
            }
        })
    },
    popularityRank: function(){
        yingo.ajax({
            params : {},
            url: '/api/trip/popularityRank',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onPopularityRankBack(result);
            }
        })
    },
    visit: function(userId,search){
        yingo.ajax({
            params : {visitorId:userId,search:search},
            url: '/api/trip/visit',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onVisitBack(result);
            }
        })
    },
    blocks: function(){
        yingo.ajax({
            params : {},
            url: '/api/trip/blocks',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onBlockList(result);
            }
        })
    },
    block: function(blockUserId){
        yingo.ajax({
            params : {blockUserId:blockUserId},
            url: '/api/trip/block',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onBlockBack(result);
            }
        })
    },
    unblocks: function(blockUserId){
        yingo.ajax({
            params : {blockUserId:blockUserId},
            url: '/api/trip/unblock',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onUnblockBack(result);
            }
        })
    },
    setMark: function(flag){
        yingo.ajax({
            params : {flag:flag},
            url: '/api/user/mark',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onUserMark(result);
            }
        })
    },
    clearMark: function(flag){
        yingo.ajax({
            params : {flag:flag},
            url: '/api/user/clearMark',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onUserMark(result);
            }
        })
    },
    activeList: function(){
        yingo.ajax({
            params : {},
            url: '/api/activity/list',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onActivityList(result);
            }
        })
    },
    chargeInfo: function(){
        yingo.ajax({
            params : {},
            url: '/api/acharge/info',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onChargeInfo(result);
            }
        })
    },
    chargeAward: function(type){
        yingo.ajax({
            params : {type:type},
            url: '/api/acharge/award',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onChargeAward(result);
            }
        })
    },
    vips: function(){
        yingo.ajax({
            params : {},
            url: '/api/data/vips',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onVipConfig(result);
            }
        })
    },
    vipInfo: function(){
        yingo.ajax({
            params : {},
            url: '/api/vip/info',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onVipInfo(result);
            }
        })
    },
    vipScore: function(type){
        yingo.ajax({
            params : {type:type},
            url: '/api/vip/score',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onVipScore(result);
            }
        })
    },
    moneyCatInfo: function(){
        yingo.ajax({
            params : {},
            url: '/api/fortune/info',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onMoneyCatInfo(result);
            }
        })
    },
    moneyCatAward: function(grade){
        yingo.ajax({
            params : {grade:grade},
            url: '/api/fortune/award',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onMoneyCatAward(result);
            }
        })
    },
    washInfo: function(petId){
        yingo.ajax({
            params : {petId:petId},
            url: '/api/wash/info',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onWashInfo(result);
            }
        })
    },
    wash: function(petId){
        yingo.ajax({
            params : {petId:petId},
            url: '/api/wash/wash',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onWashBack(result);
            }
        })
    },
    battleRecord: function(){
        yingo.ajax({
            params : {},
            url: '/api/pet/pillage-record',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onBattleRecord(result);
            }
        })
    },
    clearPeaceBuff: function(param1,param2){
        yingo.ajax({
            params : {param1:param1,param2:param2},
            url: '/api/pet/declare-war',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onWarBuffClear(result);
            }
        })
    },
    popularityAward: function(){
        yingo.ajax({
            params : {},
            url: '/api/rank/popularity-award',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onPopularityAward(result);
            }
        })
    },
    robAward:function(){
        yingo.ajax({
            params : {},
            url: '/api/rank/pillage-award',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onRobAward(result);
            }
        })
    },
    resetPraise:function(){
        yingo.ajax({
            params : {},
            url: '/api/trip/reset-praise',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onResetPraise(result);
            }
        })
    },
    forcePillage:function(pillagerId){
        yingo.ajax({
            params : {pillagerId:pillagerId},
            url: '/api/pet/force-pillage',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onForcePillageBack(result);
            }
        })
    },
    mine:function(){
        yingo.ajax({
            params : {},
            url: '/api/family/mine',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onMyGuild(result);
            }
        })
    },
    hall:function(){
        yingo.ajax({
            params : {},
            url: '/api/family/hall',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onGuildHall(result);
            }
        })
    },
    notice:function(notice){
        yingo.ajax({
            params : {notice:notice},
            url: '/api/family/notice',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onGuildNotice(result);
            }
        })
    },
    message:function(message){
        yingo.ajax({
            params : {message:message},
            url: '/api/family/message',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onGuildMessage(result);
            }
        })
    },
    clearBoard:function(){
        yingo.ajax({
            params : {},
            url: '/api/family/clear-board',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onGuildClearMessage(result);
            }
        })
    },
    donate:function(diamond){
        yingo.ajax({
            params : {diamond:diamond},
            url: '/api/family/donate',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onGuildDonate(result);
            }
        })
    },
    createGuild:function(name,logoId){
        yingo.ajax({
            params : {name:name, logoId:logoId},
            url: '/api/family/create',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onGuildCreate(result);
            }
        })
    },
    myApplies:function(){
        yingo.ajax({
            params : {},
            url: '/api/family/user-applies',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onMyApplies(result);
            }
        })
    },
    guildList:function(pageIndex,familyId){
        yingo.ajax({
            params : {pageIndex:pageIndex,familyId:familyId},
            url: '/api/family/list',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onGuildList(result);
            }
        })
    },
    applyList:function(pageIndex){
        yingo.ajax({
            params : {pageIndex:pageIndex},
            url: '/api/family/applies',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onGuildApplyList(result);
            }
        })
    },
    apply:function(familyId){
        yingo.ajax({
            params : {familyId:familyId},
            url: '/api/family/apply',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onGuildApplyResult(result);
            }
        })
    },
    dealApply:function(applyUserId,approve ){
        yingo.ajax({
            params : {applyUserId:applyUserId,approve:approve },
            url: '/api/family/deal-apply',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onGuildApplyDeal(result);
            }
        })
    },
    memberList:function( ){
        yingo.ajax({
            params : { },
            url: '/api/family/members',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onGuildMemberList(result);
            }
        })
    },
    quitGuild:function( ){
        yingo.ajax({
            params : { },
            url: '/api/family/quit',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onQuitGuild(result);
            }
        })
    },
    kickMember:function(kickUserId ){
        yingo.ajax({
            params : { kickUserId:kickUserId},
            url: '/api/family/kick',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onKickMember(result);
            }
        })
    },
    dismissGuild:function( ){
        yingo.ajax({
            params : { },
            url: '/api/family/disband',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onDismissGuild(result);
            }
        })
    },
    injectMedal:function( ){
        yingo.ajax({
            params : { },
            url: '/api/family/transfuse-logo',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onMedalInject(result);
            }
        })
    },
    upgradeMedal:function( ){
        yingo.ajax({
            params : { },
            url: '/api/family/upgrade-logo',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onMedalUpgrade(result);
            }
        })
    },
    clearMedal:function(byDiamond ){
        yingo.ajax({
            params : { byDiamond:byDiamond},
            url: '/api/family/scrub-logo',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onMedalClear(result);
            }
        })
    },
    saveClaerMedal:function( save){
        yingo.ajax({
            params : {save:save },
            url: '/api/family/save-scrub',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onMedalClearSave(result);
            }
        })
    },
    resetCleanTime:function( ){
        yingo.ajax({
            params : { },
            url: '/api/family/reset-transfuse-times',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onResetCleanTime(result);
            }
        })
    },
    guildLogs:function( ){
        yingo.ajax({
            params : { },
            url: '/api/family/logs',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onGuildLogs(result);
            }
        })
    },
    guildConfig:function( ){
        yingo.ajax({
            params : { },
            url: '/api/family/configs',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onGuildConfigs(result);
            }
        })
    },
    upgradeFamily:function(buildingId){
        yingo.ajax({
            params : { buildingId:buildingId},
            url: '/api/family/upgrade',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onUpgradeFamilyBuilding(result);
            }
        })
    },
    speedupFamily:function(buildingId){
        yingo.ajax({
            params : { buildingId:buildingId},
            url: '/api/family/speedup',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onSpeedUp(result);
            }
        })
    },
    buyGuildGoods:function(goodsId,count){
        yingo.ajax({
            params : { goodsId:goodsId,count:count },
            url: '/api/family/buy-goods',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onGuildGoodsBuy(result);
            }
        })
    },
    buyMachine:function(machineId){
        yingo.ajax({
            params : { machineId:machineId },
            url: '/api/family/buy-machine',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onBuyMachineBuy(result);
            }
        })
    },
    donateGoods:function(goodsId,count){
        yingo.ajax({
            params : { goodsId:goodsId,count:count },
            url: '/api/family/donate-goods',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onGuildDonateGoods(result);
            }
        })
    },
    exchangePrestige:function(goodsId,count){
        yingo.ajax({
            params : { goodsId:goodsId,count:count },
            url: '/api/family/exchange-prestige',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onPrestigeExchange(result);
            }
        })
    },
    chipses:function(){
        yingo.ajax({
            params : {  },
            url: '/api/family/chipses',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onMyChipsets(result);
            }
        })
    },
    exchangeChips:function(serialId){
        yingo.ajax({
            params : { serialId:serialId },
            url: '/api/family/exchange-chips',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onExchangeChips(result);
            }
        })
    },
    machines:function(){
        yingo.ajax({
            params : {  },
            url: '/api/family/machines',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onMyMachines(result);
            }
        })
    },
    visitFactory:function(visitorId){
        yingo.ajax({
            params : { visitorId:visitorId },
            url: '/api/family/visit',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onOthersFactory(result);
            }
        })
    },
    maintain:function(visitorId,machineId){
        yingo.ajax({
            params : { visitorId:visitorId,machineId:machineId },
            url: '/api/family/maintain',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onMachineMantance(result);
            }
        })
    },
    refuel:function(visitorId,machineId){
        yingo.ajax({
            params : { visitorId:visitorId,machineId:machineId },
            url: '/api/family/refuel',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onMachineFuel(result);
            }
        })
    },
    upgradeMachine:function(machineId){
        yingo.ajax({
            params : { machineId:machineId },
            url: '/api/family/upgrade-machine',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onMachineUpgrade(result);
            }
        })
    },
    speedMachineUpgrade:function(visitorId,machineId){
        yingo.ajax({
            params : { visitorId:visitorId,machineId:machineId },
            url: '/api/family/upgrade-machine-speedup',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onMachineSpeedupUpgrade(result);
            }
        })
    },
    machineProduce:function(machineId,goodsId){
        yingo.ajax({
            params : { machineId:machineId,goodsId:goodsId },
            url: '/api/family/produce-product',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onMachineProduce(result);
            }
        })
    },
    speedUpProduce:function(visitorId,machineId){
        yingo.ajax({
            params : { machineId:machineId,visitorId:visitorId },
            url: '/api/family/produce-product-speedup',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onMachineSpeedupProduce(result);
            }
        })
    },
    getMachinProduct:function(machineId){
        yingo.ajax({
            params : { machineId:machineId },
            url: '/api/family/reap-product',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onGetMachineProduct(result);
            }
        })
    },
    stopMachineProduce:function(machineId){
        yingo.ajax({
            params : { machineId:machineId },
            url: '/api/family/stop-produce',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onStopMachine(result);
            }
        })
    },
    refreshMaterial:function(){
        yingo.ajax({
            params : {  },
            url: '/api/family/refresh-chips',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onChipsRefresh(result);
            }
        })
    },
    unlockBox:function(type){
        yingo.ajax({
            params : { type:type },
            url: '/api/family/unlock-box',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onBoxUnlock(result);
            }
        })
    },
    factoryLog:function(){
        yingo.ajax({
            params : {  },
            url: '/api/family/factory-logs',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onFactoryLogs(result);
            }
        })
    },
    desktop:function(){
        yingo.ajax({
            params : {  },
            url: '/api/user/desktop',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onDesktop(result);
            }
        })
    },
    sellMaterial:function(goodsId,count){
        yingo.ajax({
            params : {goodsId:goodsId, count:count},
            url: '/api/family/sell-material',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onMaterialSold(result);
            }
        })
    },
    refreshMachine:function(visitorId,machineId){
        yingo.ajax({
            params : {visitorId:visitorId,machineId:machineId },
            url: '/api/family/refresh-machine',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onMachineRefreshed(result);
            }
        })
    },
    refreshFamily:function(){
        yingo.ajax({
            params : {visitorId:visitorId,machineId:machineId },
            url: '/api/family/refresh',
            codes:window.codes,
            callback: function (result) {
                //no callback needed
            }
        })
    },
    limitHairInfo:function(){
        yingo.ajax({
            params : {},
            url: '/api/time-limited/hair-info',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onLimitHairBack(result);
            }
        })
    },
    limitHairBuy:function(){
        yingo.ajax({
            params : {},
            url: '/api/time-limited/hair-award',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onLimitHairBuyBack(result);
            }
        })
    },
    richManInfo:function(){
        yingo.ajax({
            params : {},
            url: '/api/zillionaire/info',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onRichManInfo(result);
            }
        })
    },
    richManGo:function(){
        yingo.ajax({
            params : {},
            url: '/api/zillionaire/crap',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onRichManGo(result);
            }
        })
    },
    limitDecInfo:function(){
        yingo.ajax({
            params : {},
            url: '/api/time-limited/ornament-info',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onLimitDecInfo(result);
            }
        })
    },
    limitDecBuy:function(){
        yingo.ajax({
            params : {},
            url: '/api/time-limited/ornament-buy',
            codes:window.codes,
            callback: function (result) {
                QZoneConfig.onLimitDecBuy(result);
            }
        })
    }
};
var QZoneConfig;
window["__limitDecInfo"] = communicator.limitDecInfo;
window["__limitDecBuy"] = communicator.limitDecBuy;
window["__richManGo"] = communicator.richManGo;
window["__richManInfo"] = communicator.richManInfo;
window["__limitHairBuy"] = communicator.limitHairBuy;
window["__limitHairInfo"] = communicator.limitHairInfo;
window["__refreshFamily"] = communicator.refreshFamily;
window["__refreshMachine"] = communicator.refreshMachine;
window["__sellMaterial"] = communicator.sellMaterial;
window["__desktop"] = communicator.desktop;
window["__factoryLog"] = communicator.factoryLog;
window["__refreshMaterial"] = communicator.refreshMaterial;
window["__unlockBox"] = communicator.unlockBox;
window["__stopMachineProduce"] = communicator.stopMachineProduce;
window["__getMachinProduct"] = communicator.getMachinProduct;
window["__speedUpProduce"] = communicator.speedUpProduce;
window["__machineProduce"] = communicator.machineProduce;
window["__speedMachineUpgrade"] = communicator.speedMachineUpgrade;
window["__upgradeMachine"] = communicator.upgradeMachine;
window["__refuel"] = communicator.refuel;
window["__maintain"] = communicator.maintain;
window["__visitFactory"] = communicator.visitFactory;
window["__machines"] = communicator.machines;
window["__exchangeChips"] = communicator.exchangeChips;
window["__chipses"] = communicator.chipses;
window["__exchangePrestige"] = communicator.exchangePrestige;
window["__donateGoods"] = communicator.donateGoods;
window["__upgradeFamily"] = communicator.upgradeFamily;
window["__speedupFamily"] = communicator.speedupFamily;
window["__buyGuildGoods"] = communicator.buyGuildGoods;
window["__buyMachine"] = communicator.buyMachine;
window["__guildConfig"] = communicator.guildConfig;
window["__guildLogs"] = communicator.guildLogs;
window["__resetCleanTime"] = communicator.resetCleanTime;
window["__kickMember"] = communicator.kickMember;
window["__dismissGuild"] = communicator.dismissGuild;
window["__injectMedal"] = communicator.injectMedal;
window["__upgradeMedal"] = communicator.upgradeMedal;
window["__clearMedal"] = communicator.clearMedal;
window["__saveClaerMedal"] = communicator.saveClaerMedal;
window["__quitGuild"] = communicator.quitGuild;
window["__memberList"] = communicator.memberList;
window["__mine"] = communicator.mine;
window["__hall"] = communicator.hall;
window["__notice"] = communicator.notice;
window["__message"] = communicator.message;
window["__clearBoard"] = communicator.clearBoard;
window["__donate"] = communicator.donate;
window["__createGuild"] = communicator.createGuild;
window["__myApplies"] = communicator.myApplies;
window["__guildList"] = communicator.guildList;
window["__applyList"] = communicator.applyList;
window["__apply"] = communicator.apply;
window["__dealApply"] = communicator.dealApply;
window["__resetPraise"] = communicator.resetPraise;
window["__forcePillage"] = communicator.forcePillage;
window["__popularityAward"] = communicator.popularityAward;
window["__robAward"] = communicator.robAward;
window["__clearPeaceBuff"] = communicator.clearPeaceBuff;
window["__battleRecord"] = communicator.battleRecord;
window["__robHairs"] = communicator.robHairs;
window["__userPopularity"] = communicator.userPopularity;
window["__washInfo"] = communicator.washInfo;
window["__wash"] = communicator.wash;
window["__moneyCatInfo"] = communicator.moneyCatInfo;
window["__moneyCatAward"] = communicator.moneyCatAward;
window["__vipInfo"] = communicator.vipInfo;
window["__vipScore"] = communicator.vipScore;
window["__vips"] = communicator.vips;
window["__activeList"] = communicator.activeList;
window["__chargeInfo"] = communicator.chargeInfo;
window["__chargeAward"] = communicator.chargeAward;
window["__clearMark"] = communicator.clearMark;
window["__setMark"] = communicator.setMark;
window["__blocks"] = communicator.blocks;
window["__block"] = communicator.block;
window["__unblocks"] = communicator.unblocks;
window["__dunlocks"] = communicator.dunlocks;
window["__cleancd"] = communicator.cleancd;
window["__visit"] = communicator.visit;
window["__pillageFinish"] = communicator.pillageFinish;
window["__revenge"] = communicator.revenge;
window["__lattention"] = communicator.lattention;
window["__popularity"] = communicator.popularity;
window["__popularityRank"] = communicator.popularityRank;
window["__pillage"] = communicator.pillage;
window["__handsel"] = communicator.handsel;
window["__praise"] = communicator.praise;
window["__attention"] = communicator.attention;
window["__unattention"] = communicator.unattention;
window["__search"] = communicator.search;
window["__buydecorates"] = communicator.buydecorates;
window["__dressup"] = communicator.dressup;
window["__iwars"] = communicator.iwars;
window["__iornaments"] = communicator.iornaments;
window["__dmodels"] = communicator.decoratemodels;
window["__unlocks"] = communicator.unlocks;
window["__changeRear"] = communicator.changeRear;
window["__mailAward"] = communicator.mailAward;
window["__deleteMail"] = communicator.deleteMail;
window["__readMail"] = communicator.readmail;
window["__mailList"] = communicator.maillist;
window["__sign"] = communicator.sign;
window["__signInfo"] = communicator.signInfo;
window["__missionAward"] = communicator.missionAward;
window["__missionList"] = communicator.missionList;
window["__models"] = communicator.models;
window["__updateSlogan"] = communicator.updateSlogan;
window["__setFigure"] = communicator.setFigure;
window["__buffs"] = communicator.buffs;
window["__use"] = communicator.use;
window["__petFondle"] = communicator.petFondle;
window["__petHair"] = communicator.petHair;
window["__userHair"] = communicator.userHair;
window["__petHairs"] = communicator.petHairs;
window["__petSex"] = communicator.petSex;
window["__petCount"] = communicator.petCount;
window["__dateSweep"] = communicator.dateSweep;
window["__dateRefresh"] = communicator.dateRefresh;
window["__dateInfo"] = communicator.dateInfo;
window["__indate"] = communicator.indate;
window["__date"] = communicator.date;
window["__upgrade"] = communicator.upgrade;
window["__glean"] = communicator.glean;
window["__auto"] = communicator.auto;
window["__click"] = communicator.click;
window["__fondle"] = communicator.fondle;
window["__guide"] = communicator.guide;
window["__gift"] = communicator.gift;
window["__buy_prop"] = communicator.buy_prop;
window["__use_prop"] = communicator.use_prop;
window["__zoneInfo"] = communicator.zoneInfo;
window["__props"] = communicator.props;
window["__rankPage"] = communicator.rankPage;
window["__charge"] = communicator.charge;//star to diamond
window["__pay"] = communicator.pay;
window["__goods"] = communicator.goods;
window["__buy"] = communicator.buy;
window["__heartbeat"] = communicator.heartbeat;
window["__joinGroup"] = yingo.joinGroup;
function paySucess(){
    QZoneConfig.onPaySuccessBack();
}
window["__paySuccess"] = paySucess;
function payError(){
    yingo.notification("支付失败");
}
window["__payError"] = payError;
function payClose(){
    yingo.notification("支付已取消");
}
window["__payClose"] = payClose;

function showConnection(isShown){
    connectingDiv.style.display = isShown ? "block" : "none";
}
window["__showConnection"] = showConnection;

/////-------------------websocket related-------------------/////
var serviceManager;
var messageHandler
function startWebSocket(){
    serviceManager = new ServiceManager(window.server, function (event) {
        serviceManager.invoke("/ws/game/auth", {
            "x-auth-token": window.xtoken
        }, function (data) {
            messageHandler = egret.getDefinitionByName("game.BroadcastHandler");
            messageHandler.updateConnectionStat(true);
            serviceManager.addPushHandler("Chat.world",function(data){
                messageHandler.handle(data);
            });
            serviceManager.addPushHandler("Chat.personal",function(data){
                messageHandler.handle(data);
            });
            serviceManager.addPushHandler("UserProp.remove",function(data){
                messageHandler.handle(data);
            });
            serviceManager.addPushHandler("UserOrnament.remove",function(data){
                messageHandler.handle(data);
            });
            serviceManager.addPushHandler("TimerBuff.remove",function(data){
                messageHandler.handle(data);
            });
            serviceManager.addPushHandler("TimerBuff.add",function(data){
                messageHandler.handle(data);
            });
            serviceManager.addPushHandler("UserMail.add",function(data){
                messageHandler.handle(data);
            });
            serviceManager.addPushHandler("UserMail.remove",function(data){
                messageHandler.handle(data);
            });
            serviceManager.addPushHandler("UserMission.list",function(data){
                messageHandler.handle(data);
            });
            serviceManager.addPushHandler("Pet.hair",function(data){
                messageHandler.handle(data);
            });
            serviceManager.addPushHandler("Pet.petHair",function(data){
                messageHandler.handle(data);
            });
            serviceManager.addPushHandler("PetWar.list",function(data){
                messageHandler.handle(data);
            });
            serviceManager.addPushHandler("Activity.charge",function(data){
                messageHandler.handle(data);
            });
            serviceManager.addPushHandler("Activity.fortuneCat",function(data){
                messageHandler.handle(data);
            });
            serviceManager.addPushHandler("Activity.vipScore",function(data){
                messageHandler.handle(data);
            });
            serviceManager.addPushHandler("User.update",function(data){
                messageHandler.handle(data);
            });
            serviceManager.addPushHandler("UserExtendInfo.update",function(data){
                messageHandler.handle(data);
            });
            serviceManager.addPushHandler("Chat.system",function(data){
                messageHandler.handle(data);
            });
            serviceManager.addPushHandler("Family.apply",function(data){
                messageHandler.handle(data);
            });
            serviceManager.addPushHandler("Family.kickout",function(data){
                messageHandler.handle(data);
            });
            serviceManager.addPushHandler("Family.approve",function(data){
                messageHandler.handle(data);
            });
            serviceManager.addPushHandler("Family.disband",function(data){
                messageHandler.handle(data);
            });
            serviceManager.addPushHandler("Family.reject",function(data){
                messageHandler.handle(data);
            });
            serviceManager.addPushHandler("Family.member.approve",function(data){
                messageHandler.handle(data);
            });
            serviceManager.addPushHandler("Family.member.kick",function(data){
                messageHandler.handle(data);
            });
            serviceManager.addPushHandler("Family.member.quit",function(data){
                messageHandler.handle(data);
            });
            serviceManager.addPushHandler("Family.machies.reap",function(data){
                messageHandler.handle(data);
            });
            serviceManager.addPushHandler("Family.machies.upgrade",function(data){
                messageHandler.handle(data);
            });
            serviceManager.addPushHandler("Family.machies.refuel",function(data){
                messageHandler.handle(data);
            });
            serviceManager.addPushHandler("Family.machies.maintain",function(data){
                messageHandler.handle(data);
            });
            serviceManager.addPushHandler("Family.warehouse.boxes",function(data){
                messageHandler.handle(data);
            });

            serviceManager.addPushHandler("Family.message.add",function(data){
                messageHandler.handle(data);
            });
            serviceManager.addPushHandler("Family.message.clean",function(data){
                messageHandler.handle(data);
            });
            serviceManager.addPushHandler("Family.machine",function(data){
                messageHandler.handle(data);
            });
            serviceManager.addPushHandler("Family.data",function(data){
                messageHandler.handle(data);
            });
            serviceManager.addPushHandler("Activity.timeLimitedHair",function(data){
                messageHandler.handle(data);
            });
            serviceManager.addPushHandler("Activity.timeLimitedOrnament",function(data){
                messageHandler.handle(data);
            });
            window.setInterval(function () {
                serviceManager.invoke("/ws/game/heartbeat");
            }, 5 * 60 * 1000);
        }, function (data) {
            console.log("ecallback", data);
        });
    }, function (event) {
        if(messageHandler)
            messageHandler.updateConnectionStat(false,event.code);
        console.log("session closed :", event.code, event.reason);
    }, function (event) {
    });
    serviceManager.connect();
}
function invoke(serveurl,params,callback,errorCallback){
    serviceManager.invoke(serveurl,params,callback,errorCallback);
}
function sendToUser(userId,message){
    serviceManager.invoke("/ws/chat/personal",{
            message:message,
            userId:userId
        }, onChatBack,  onWsError)
}
function sendToWorld(message){
    serviceManager.invoke("/ws/chat/world",{
        message:message
    }, onWorldBack, onWsError)
}
function onChatBack(result){
    console.log("chat message back");
    var chatMgr = egret.getDefinitionByName("ChatMgr");
    if( chatMgr)
        chatMgr.getInstance().onPersonalChatback(result);
}
function onWorldBack(result){
    console.log("world message back");
    var model = egret.getDefinitionByName("Model");
    if(model)
        model.LastChatTime = result.lastWorldTime;
}
function onWsError(data){
    console.log("ws error back");
}
window["__startWS"] = startWebSocket;
window["__sendToUser"] = sendToUser;
window["__sendToWorld"] = sendToWorld;